USE [influenza]
GO

/****** Object:  StoredProcedure [dbo].[SP_RecAuxLabResC]    Script Date: 03/04/2010 09:19:16 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


ALTER PROCEDURE [dbo].[SP_RecAuxLabResC]
@param varchar(100)
as
Begin
declare 
 @qry varchar(8000),
 @nRegistro varchar(10),
 @nProc varchar(10),
 @id_muestras varchar(50)
 
 set @nRegistro=influenza.dbo.fnSplit(@param,'|',1);
 set @nProc=influenza.dbo.fnSplit(@param,'|',2);
 set @id_muestras=influenza.dbo.fnSplit(@param,'|',3);
 
set @qry='select distinct a.nTecnica,a.nResultado, b.id_lab_Estudio as nEstudio,c.id_laboratorio,  
convert(varchar(10),a.fResultado,103) as fResultado, 
nProc,id_resultado,id_dat_registro,CONVERT(varchar(10),fTermino,103) as fTermino,id_resultado as id_auxLabRes
from aux_laboratorio_res a
left join cat_AdminLab b on(b.id_lab_tecnica=a.nTecnica and b.id_lab_resultado=a.nResultado and a.nProc=b.id_lab_proc) 
inner join dat_laboratorio c on(c.id_principal=a.id_dat_laboratorio)
left join dat_registro d on (d.id_principal = c.id_registro)
inner join aux_muestras e on (d.id_principal = e.id_principal and c.nTipomuestra=e.nTipomuestra)
where a.id_dat_registro='+@nRegistro+' and a.nProc='+@nProc+' and e.id_muestras='+@id_muestras

 exec(@qry)

End
GO

